package com.xiaolin.sports.aliyun.mns;

import java.rmi.ServerException;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsRequest;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsResponse;

public class TestSms {
	
	public static String regionId="cn-shenzhen";//机房信息,可以不用更改
	/**********需要准备的参数**************/
	public static String accessKey="LTAIcqhZbV3T83IR";//需要修改
	public static String accessSecret="E11b5rwteGj8YlDQ4roMHYZDiRe2c2";//需要修改
	public static String code="SMS_66630032";//需要修改
	public static String signName="小林体育";//需要修改
	
	public static void main(String[] args) {
		String phone="13681984045";  
        //根据自己定义的短信模板，修改  
        String jsonStr="{\"code\":\"12312\"}";  
        try {
			test(phone, jsonStr);
		} catch (ServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

	public static void test(String phone, String jsonStr) throws ServerException {        
		   try {
	        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKey, accessSecret);
	        DefaultProfile.addEndpoint("cn-shenzhen", "cn-shenzhen", "Sms",  "sms.aliyuncs.com");
	        IAcsClient client = new DefaultAcsClient(profile);
	        SingleSendSmsRequest request = new SingleSendSmsRequest();
	            //管理控制台中配置的短信签名（状态必须是验证通过）
	            request.setSignName(signName);
	            //管理控制台中配置的审核通过的短信模板的模板CODE（状态必须是验证通过）
	           request.setTemplateCode(code);
	            request.setParamString(jsonStr);
	            //目标手机号，多个手机号可以逗号分隔
	            request.setRecNum(phone);
	            
	            SingleSendSmsResponse httpResponse = client.getAcsResponse(request);
	            String requestId = httpResponse.getRequestId();
	            System.err.println("requestId:"+requestId);
	        } catch (ClientException e) {
	            e.printStackTrace();
	        }
	    }

}
